PORTING_ROOT_DIR ?= $(shell cd $(CURDIR)/../.. && /bin/pwd)

include $(PORTING_ROOT_DIR)/porting_base.mk

DST_DIR := /nfsdir/
OSD_DIR := $(PORTING_ROOT_DIR)/sample/venc/osd/

TARGET := sample_vio
HTTP_SERVER_DIR= $(PORTING_ROOT_DIR)/sample/venc/http_server

LDFLAGS += -L $(PORTING_ROOT_DIR)/sample/venc/rtsp_lib/ -L$(PORTING_ROOT_DIR)/sample/venc/osd/
LDFLAGS += -L $(PORTING_ROOT_DIR)/sample/venc/zstd/lib/
LDFLAGS += -L$(PORTING_ROOT_DIR)/sample/venc/lz4/lib
LDFLAGS += -L$(PORTING_ROOT_DIR)/sample/rtsp/lib

LDFLAGS += -I$(PORTING_ROOT_DIR)/sample/venc/rtsp_lib/ -I$(PORTING_ROOT_DIR)/sample/venc/osd/ -I$(PORTING_ROOT_DIR)/sample/venc/discovery_private_devices/
LDFLAGS += -I$(PORTING_ROOT_DIR)/sample/venc/zstd/include/ -I$(PORTING_ROOT_DIR)/sample/venc/queue/
#add http server
LDFLAGS += -I$(HTTP_SERVER_DIR)/src/ -I$(HTTP_SERVER_DIR)/include -I$(HTTP_SERVER_DIR)/cjson -I$(HTTP_SERVER_DIR)/http	\
-I$(HTTP_SERVER_DIR)/mongoose/ -I$(HTTP_SERVER_DIR)/list/

#add thpool
LDFLAGS += -I$(PORTING_ROOT_DIR)/sample/thpool/
LDFLAGS += -I$(PORTING_ROOT_DIR)/sample/udp_transport/ -I./

#add lz4
LDFLAGS += -I$(PORTING_ROOT_DIR)/sample/venc/lz4/include

LDFLAGS += -lrtsp -llz4
# -lzstd

CFLAGS := $(PORTING_CFLAGS) $(PORTING_LIBS)
DST_DIR := /nfsdir/
DST_DIR2 := /nfsdir/tftp_files/

CFLAGS += -g 
# -DSEND_BMP8_2_NV12
SRCS := $(wildcard ./*.c)
SRCS += $(wildcard $(PORTING_ROOT_DIR)/sample/venc/osd/*.c)
SRCS += $(wildcard $(PORTING_ROOT_DIR)/sample/venc/discovery_private_devices/*.c)
SRCS += $(wildcard $(PORTING_ROOT_DIR)/sample/venc/network/*.c)
SRCS += $(wildcard $(PORTING_ROOT_DIR)/sample/venc/ini_parser/src/*.c)
SRCS += $(wildcard $(PORTING_ROOT_DIR)/sample/venc/uart/*.c)
#add http_server
SRCS += $(wildcard $(HTTP_SERVER_DIR)/src/*.c)
SRCS += $(wildcard $(HTTP_SERVER_DIR)/cjson/*.c)
SRCS += $(HTTP_SERVER_DIR)/http/http_server.c
SRCS += $(wildcard $(HTTP_SERVER_DIR)/mongoose/*.c)
SRCS += $(wildcard $(HTTP_SERVER_DIR)/list/*.c)

#add thpool
SRCS += $(wildcard $(PORTING_ROOT_DIR)/sample/thpool/*.c)
#add queue
SRCS += $(wildcard $(PORTING_ROOT_DIR)/sample/venc/queue/*.c)
SRCS += $(wildcard $(PORTING_ROOT_DIR)/sample/udp_transport/*.c)



OBJS := $(patsubst %.c, %.o, $(SRCS))

.PHONY: all clean

all: $(OBJS)
	$(AT)$(CC) -o $(TARGET) $^ $(CFLAGS) $(LDFLAGS)
#	$(AT)cp -rf $(TARGET) $(DST_DIR)

%.o : %.c
	$(AT)$(CC) -c -o $@ $< $(CFLAGS)  $(LDFLAGS)

clean:
	$(AT)rm -rf $(OBJS) $(TARGET) \
	$(HTTP_SERVER_DIR)/cjson/*.o $(HTTP_SERVER_DIR)/http/*.o $(HTTP_SERVER_DIR)/list/*.o $(HTTP_SERVER_DIR)/mongoose/*.o $(HTTP_SERVER_DIR)/src/*.o \
	$(INI_PARSER_DIR)/src/*.o	\

